﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using Microsoft.WindowsAPICodePack.Shell;

namespace UIWPF
{
    /// <summary>
    /// Interaction logic for StartWindow.xaml
    /// </summary>
    public partial class StartWindow : Window
    {
        private bool _tmFlag = true;
        private bool _doHiding = false;
        private DispatcherTimer tm = new DispatcherTimer();

        public StartWindow()
        {
            InitializeComponent();

            tm.Tick += TickGradual;
            tm.Interval = TimeSpan.FromSeconds(0.01);
        }

        private void TickGradual(object sender, EventArgs e)
        {
            if (_tmFlag)
            {
                Opacity += 0.02;
                if (Opacity >= 1.0)
                {
                    tm.Stop();
                }
            }
            else
            {
                Opacity -= 0.02;
                if (Opacity <= 0.0)
                {
                    if (_doHiding)
                    {
                        tm.Stop();
                        Hide();
                    }
                    else
                    {
                        Close();
                    }
                }
            }
        }

        private void doOpening()
        {
            Show();
            Opacity = 0.0;
            _tmFlag = true;
            tm.Start();
        }
        private void doClosing()
        {
            _doHiding = false;
            _tmFlag = false;
            tm.Start();
        }
        private void doHiding()
        {
            _doHiding = true;
            _tmFlag = false;
            tm.Start();
        }

        private void BtnExitClick(object sender, RoutedEventArgs e)
        {
            MyMessageBox.Show("Good Bye~");
            doClosing();
        }

        private void FormLoading(object sender, RoutedEventArgs e)
        {
            Opacity = 0;
            doOpening();
        }

        private void DragWindowMouseMove(object sender, MouseEventArgs e)
        {
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                DragMove();
            }
        }

        private void BtnCodeCompareClick(object sender, RoutedEventArgs e)
        {
//            MyMessageBox.Show("Open Code Compare Window.");
            CodeCompareWindow ccw = new CodeCompareWindow();
            doHiding();
            ccw.ShowDialog();
            ccw.Close();
            doOpening();
        }

        private void BtnAboutMeClick(object sender, RoutedEventArgs e)
        {
            MyMessageBox.Show("About Me.");
        }

        private void BtnFolderCompareClick(object sender, RoutedEventArgs e)
        {
            FolderCompareWindow fcw = new FolderCompareWindow();
            doHiding();
            fcw.ShowDialog();
            fcw.Close();
            doOpening();
        }
    }
}
